<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?=form_hidden("ID", $this->input->post("ID"))?>
<?=form_hidden("ENTITY", $this->input->post("ENTITY"))?>

<div class="form-group">
	<?=form_label($this->lang->line("NAME_OF_THE_ACCOMODATION"), "acc_name", array("class" => "control-label"))?>
	<?=form_input("acc_name", (isset($getAccomodation[0]["accName"]) ? $getAccomodation[0]["accName"] : null), "placeholder=\"".$this->lang->line("NAME_OF_THE_ACCOMODATION")."\" class=\"form-control\" id=\"acc_name\"")?>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("INSTITUTE"), "ins_id", array("class" => "control-label"))?>
	<?=form_dropdown("ins_id[]", $getInstituteList, (isset($getAccomodation[0]["insList"]) ? explode(",", $getAccomodation[0]["insList"]) : null), "id=\"ins_id\" style=\"width: 100%;\" multiple")?>
	<script>
		$(function() {
			$('#ins_id').select2();
		});
	</script>
</div>

<div class="form-group">
	<?=form_label($this->lang->line("CITY"), "acc_city_id", array("class" => "control-label"))?>
	<?=form_input("acc_city_id", (isset($getAccomodation[0]["accCityId"]) ? $getAccomodation[0]["accCityId"] : null), "style=\"width:100%;\" id=\"acc_city_id\"")?>
	<script>
		$(function() {
			$('#acc_city_id').select2({
				allowClear: true,
				placeholder: '<?=$this->lang->line("CITY")?>',
				minimumInputLength: 2,
				ajax: {
					url: '<?=site_url("admin_lte/get_city")?>',
					cache: false,
					dataType: 'json',
					data: function (term, page) {
						return {
							q: term
						};
					},
					results: function (data, page) {
						return {results: data, more: false};
					}
				},
				initSelection: function(element, callback) {
					var id=$(element).val();
					if (id!=="") {
						$.ajax('<?=site_url("admin_lte/get_city")?>', {
							data: {
								id: id
							},
							cache: false,
							dataType: "json"
						}).done(function(data) { callback(data); });
					}
				},
				formatSelection: function(a, b, c) {
					if($.isArray(a)) {
						return a[0].text;
					}
					return a.text;
				},
				escapeMarkup: function (m) { return m; }
			});
		});
	</script>
</div>

<? //Common::pr($getCategoryVal); ?>

<?=Common::generateForm($getCategoryVal)?>

<script>
	$(function() {
		if($('#cat_<?=$this->config->item("categoryACCAddress")?>').length) {
			$('#cat_<?=$this->config->item("categoryACCAddress")?>').blur(function() {
				var geocoder = new google.maps.Geocoder();
				geocoder.geocode( { address: $(this).val() }, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						$('#acc_latitude').val(results[0].geometry.location.lat());
						$('#acc_longitude').val(results[0].geometry.location.lng());
					}
				})
			});
		}

		$('#marker').addClass('cp').click(function() {
			if($('#acc_latitude').val() && $('#acc_longitude').val()) {
				$('#studySecondaryDisplayModal .modal-title').html('<?=$this->lang->line("GOOGLE_MAP")?>');
				$('#studySecondaryDisplayModal .modal-body').height(500);
				$('#studySecondaryDisplayModal').modal('toggle');

				$('#studySecondaryDisplayModal').on('shown.bs.modal', function () { 
					var mapOptions = {
						center: new google.maps.LatLng($('#acc_latitude').val(), $('#acc_longitude').val()),
						zoom: 14,
						mapTypeId: google.maps.MapTypeId.ROADMAP
					};
					var map = new google.maps.Map($('#studySecondaryDisplayModal .modal-body')[0], mapOptions);
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng($('#acc_latitude').val(), $('#acc_longitude').val())
					});
					marker.setMap(map);
				});
			}
		});

		$('.fileBox').bind('dragover', function() { $(this).css('borderColor', 'black')});
		$('.fileBox').bind('dragleave', function() { $(this).css('borderColor', '#cccccc')});
		$('.fileBox').bind('drop', function() { $(this).css('borderColor', '#cccccc')});
		
		$(document).bind('drop dragover', function (e) {
			e.preventDefault();
		});

	});
</script>